﻿using AutoMapper;
using Hotel.Common;
using Hotel.Domain;
using Hotel.IServices;
using Hotel.IServices.RequestDTO;
using Hotel.IServices.ResponseDTO;
using Hotel.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class UserController : ControllerBase
    {
        private readonly IAddUserServuces addUserServuces;
        private readonly ILogger<AddUserServuces> logger;
        private readonly IMapper mapper;

        public UserController(IAddUserServuces addUserServuces, ILogger<AddUserServuces> logger, IMapper mapper)
        {
            this.addUserServuces = addUserServuces;
            this.logger = logger;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        /// 
        [HttpPost("AddUser")]
        public async Task<ApiResult> AddUser(AddUserAsyncDto param)
        {
            try
            {
            
                return await addUserServuces.AddUser(param);
            }
            catch (Exception ex)
            {
                logger.LogError("InsertDatasErros:" + ex.Message);
                throw;
            }
        }


        /// <summary>
        /// 分页 显示 用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet("ShowUser")]
        public async Task<ApiResult<PagingResult<IList<GetUserResDto>>>> ShowUser([FromQuery]GetUserPageDto dto)
        {
            return await addUserServuces.ShowUser(dto);
        }


        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        /// 
        [HttpDelete("DelUser")]
        public async Task<ApiResult> DelUser(int uid)
        {
      
              return  await addUserServuces.DelUser(uid);
        }



        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="Uid"></param>
        /// <returns></returns>
        /// 
        [HttpGet("UpSqlUser")]
        public async Task<ApiResult> UpSqlUser(int Uid)
        {
            return await addUserServuces.UpSqlUser(Uid);
        }




        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPut("UpUser")]
        public async Task<ApiResult> UpUser(GetUpUserResDto dto)
        {
          
            return await addUserServuces.UpUser(dto);
        }
    }
}
